import cv2
import numpy as np


class ImageFileReader(object):
    def __init__(self, bytes_imgs):
        self.bytes_imgs = bytes_imgs
        self.num = len(bytes_imgs)

    def __iter__(self):
        self.count = 0
        return self

    def __next__(self):
        if self.count == self.num:
            raise StopIteration
        img_arr = cv2.imdecode(np.frombuffer(self.bytes_imgs[self.count], np.uint8), cv2.IMREAD_COLOR)
        self.count += 1
        return img_arr

    def __len__(self):
        return self.num
